using ASP;
using HoWave.Alipay;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.DataHelper;
using HoWave.Web.Shop.Member;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;
public class Member_Application : Member, IRequiresSessionState
{
	protected DropDownList payment_sel;
	protected HtmlInputText shoukuan_name;
	protected HtmlInputText shoukuan_bank;
	protected HtmlInputText account;
	protected HtmlInputText price;
	protected HtmlTextArea memberremark;
	protected Label lblPrice;
	protected Button submit;
	protected Literal ltrUserName;
	protected Literal Balance;
	protected Literal ltrFrozenMoney;
	protected HtmlInputText TxtMoney;
	protected RadioButton rdoAlipay;
	protected Button btnSubmitChage;
	protected HtmlInputText BeginTime;
	protected HtmlInputText EndTime;
	protected HtmlInputText txtPayNum;
	protected Button Button1;
	protected Repeater Repeater1;
	protected AspNetPager AspNetPager1;
	protected HtmlTable noread;
	private Shop_PayType _shop_payType = null;
	private ToCashBLL _ToCashBLL = null;
	private PayOnline _online;
	private AccountDetailsBll _payment = null;
	private int _cash_count = 0;
	private decimal _cash_price_min = 0m;
	private decimal _cash_price_max = 0m;
	private int _nowdate_cash_count = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_PayType shop_payType
	{
		get
		{
			Shop_PayType shop_payType;
			if (this._shop_payType == null)
			{
				this._shop_payType = new Shop_PayType(this.conn);
				shop_payType = this._shop_payType;
			}
			else
			{
				shop_payType = this._shop_payType;
			}
			return shop_payType;
		}
	}
	protected ToCashBLL to_ToCashBLL
	{
		get
		{
			ToCashBLL toCashBLL;
			if (this._ToCashBLL == null)
			{
				this._ToCashBLL = new ToCashBLL(this.conn);
				toCashBLL = this._ToCashBLL;
			}
			else
			{
				toCashBLL = this._ToCashBLL;
			}
			return toCashBLL;
		}
	}
	protected PayOnline cm_online
	{
		get
		{
			PayOnline online;
			if (this._online == null)
			{
				this._online = new PayOnline();
				online = this._online;
			}
			else
			{
				online = this._online;
			}
			return online;
		}
	}
	protected AccountDetailsBll m_payment
	{
		get
		{
			AccountDetailsBll payment;
			if (this._payment == null)
			{
				this._payment = new AccountDetailsBll(this.conn);
				payment = this._payment;
			}
			else
			{
				payment = this._payment;
			}
			return payment;
		}
	}
	public int cash_count
	{
		get
		{
			return this._cash_count;
		}
		set
		{
			this._cash_count = value;
		}
	}
	public decimal cash_price_min
	{
		get
		{
			return this._cash_price_min;
		}
		set
		{
			this._cash_price_min = value;
		}
	}
	public decimal cash_price_max
	{
		get
		{
			return this._cash_price_max;
		}
		set
		{
			this._cash_price_max = value;
		}
	}
	public int nowdate_cash_count
	{
		get
		{
			return this._nowdate_cash_count;
		}
		set
		{
			this._nowdate_cash_count = value;
		}
	}
	public string actType
	{
		get;
		set;
	}
	public string Stamp
	{
		get
		{
			return (string)this.ViewState["Stamp"];
		}
		set
		{
			this.ViewState["Stamp"] = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.BeginTime.Attributes.Add("onClick", "SelectDate(" + this.BeginTime.UniqueID + ",'yyyy-MM-dd')");
		this.EndTime.Attributes.Add("onClick", "SelectDate(" + this.EndTime.UniqueID + ",'yyyy-MM-dd');");
		if (!base.IsPostBack)
		{
			if (Fetch.Get("actype") == "now")
			{
				this.actType = "3";
				this.lblPrice.Text = base.user.Balance.ToString();
				this.BindPayType();
				this.Set_Cash_CountOrMoney();
			}
			else
			{
				if (Fetch.Get("actype") == "Rechar")
				{
					this.Page.Title = "充值";
					this.actType = "2";
					if (!string.IsNullOrEmpty(base.user.Balance.ToString()))
					{
						this.Balance.Text = base.user.Balance.ToString();
					}
					this.ltrUserName.Text = base.user.UserName;
					DataTable dataTable = this.conn.GetDataTable("select * from HL_User where UserID=" + base.user.UserID);
					if (!string.IsNullOrEmpty(dataTable.Rows[0]["FreezeMoney"].ToString()))
					{
						this.ltrFrozenMoney.Text = dataTable.Rows[0]["FreezeMoney"].ToString();
					}
				}
				else
				{
					if (Fetch.Get("actype") == "list")
					{
						this.Page.Title = "充值列表";
						this.actType = "1";
						this.DataBindList();
						this.ViewState["Stamp"] = "data";
					}
				}
			}
		}
	}
	private void Set_Cash_CountOrMoney()
	{
		Config config = new Config();
		DataTable config_Table = config.config_Table;
		if (config_Table != null)
		{
			if (config_Table.Rows.Count > 0)
			{
				this.cash_count = StaticFun.GetValueInt32(config_Table, 0, "Cash_Count");
				this.cash_price_min = StaticFun.GetValueDecimal(config_Table, 0, "Cash_Money_Min");
				this.cash_price_max = StaticFun.GetValueDecimal(config_Table, 0, "Cash_Money_Max");
			}
		}
		this.nowdate_cash_count = this.to_ToCashBLL.GetNowDateOfCashCount(base.user.UserID);
		if (this.cash_count > 0)
		{
			if (this.nowdate_cash_count >= this.cash_count)
			{
				this.WriteErrMsg("", "不能超过当天的提现次数" + this.cash_count + "！", "RecordChash.aspx");
			}
		}
	}
	public void DataBindList()
	{
		this.AspNetPager1.RecordCount = this.cm_online.GetByUserID(base.user.UserID).Rows.Count;
		int pageSize = this.AspNetPager1.PageSize = 10;
		int pageIndex;
		if (this.AspNetPager1.CurrentPageIndex < 1)
		{
			pageIndex = 1;
		}
		else
		{
			pageIndex = this.AspNetPager1.CurrentPageIndex;
		}
		DataTable payPageByUserID = this.cm_online.GetPayPageByUserID(pageIndex, pageSize, base.user.UserID);
		if (payPageByUserID.Rows.Count != 0)
		{
			this.Repeater1.DataSource = payPageByUserID;
			this.noread.Visible = false;
		}
		else
		{
			this.noread.Visible = true;
			this.AspNetPager1.Visible = false;
		}
		this.Repeater1.DataBind();
	}
	public void DataBindSearch()
	{
		this.AspNetPager1.RecordCount = this.cm_online.GetPayPageBySearchCount(base.user.UserID, this.BeginTime.Value.Trim(), this.EndTime.Value.Trim(), this.txtPayNum.Value).Rows.Count;
		int pageSize = this.AspNetPager1.PageSize = 10;
		int pageIndex;
		if (this.AspNetPager1.CurrentPageIndex < 1)
		{
			pageIndex = 1;
		}
		else
		{
			pageIndex = this.AspNetPager1.CurrentPageIndex;
		}
		DataTable payPageBySearch = this.cm_online.GetPayPageBySearch(pageIndex, pageSize, base.user.UserID, this.BeginTime.Value, this.EndTime.Value, this.txtPayNum.Value);
		if (payPageBySearch.Rows.Count != 0)
		{
			this.Repeater1.DataSource = payPageBySearch;
			this.noread.Visible = false;
		}
		else
		{
			this.noread.Visible = true;
			this.AspNetPager1.Visible = false;
		}
		this.Repeater1.DataBind();
	}
	public void BindPayType()
	{
	}
	protected void submit_Click(object sender, EventArgs e)
	{
		HL_AdminToCash hL_AdminToCash = new HL_AdminToCash();
		hL_AdminToCash.ToCashID = DateTime.Now.ToFileTimeUtc().ToString();
		if (this.payment_sel.SelectedValue == "线下支付")
		{
			hL_AdminToCash.Bank = this.shoukuan_bank.Value;
			hL_AdminToCash.TCAccountName = this.shoukuan_name.Value;
		}
		else
		{
			hL_AdminToCash.Bank = string.Empty;
			hL_AdminToCash.TCAccountName = string.Empty;
		}
		decimal num = Convert.ToDecimal(this.price.Value);
		this.Set_Cash_CountOrMoney();
		hL_AdminToCash.NumberType = this.payment_sel.SelectedItem.Text;
		hL_AdminToCash.MemberDesc = this.memberremark.Value;
		hL_AdminToCash.TCAccoutID = this.account.Value;
		hL_AdminToCash.TCDesc = base.user.UserName + "申请提现金额" + this.price.Value + "元";
		hL_AdminToCash.TChApplyTime = Convert.ToDateTime(DateTime.Now.ToUniversalTime().ToString());
		hL_AdminToCash.ToCashMoney = Convert.ToDouble(this.price.Value);
		hL_AdminToCash.TCStuate = 1;
		hL_AdminToCash.TCExamineTime = "未审核";
		hL_AdminToCash.UserID = base.user.UserID;
		if (Convert.ToDecimal(this.price.Value) > base.user.Balance)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/Inadequate"), "Application.aspx?actype=now");
		}
		else
		{
			bool flag = this.to_ToCashBLL.AddApplicationTransaction(hL_AdminToCash);
			if (flag)
			{
				this.WriteSuccessMsg("", Language.GetAdminMsg("Common/ChashSucess"), "RecordChash.aspx");
			}
		}
	}
	protected void btnSubmitChage_Click(object sender, EventArgs e)
	{
		if (this.rdoAlipay.Checked)
		{
			int value = 1;
			int num = Convert.ToInt32(value);
			decimal num2 = Text.ToDecimal(this.TxtMoney.Value);
			if (num2 <= 0m)
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Voucher/MoneyErr", new string[0]), "");
			}
			num2 = decimal.Round(num2, 2);
			if (num <= 0)
			{
				this.WriteErrMsg("", Language.Get("Common/NotData"), "");
			}
			OnlinePaySeting onlinePaySeting = new OnlinePaySeting(this.conn);
			string text = "";
			if (num == 1)
			{
				text = "alipay";
			}
			string text2 = DateTime.Now.ToString("yyyyMMddhhmmss") + Text.MakePassword(2);
			PayOnline payOnline = new PayOnline(this.conn);
			if (!payOnline.Add(base.user.UserID, base.user.UserName, 0, text2, num, num2, num2, "", ""))
			{
				this.WriteErrMsg("", Language.Get("Common/Fail", ""), "");
			}
			SiteConfigBll siteConfigBll = new SiteConfigBll();
			text = text.ToLower();
			string text3 = text;
			if (text3 != null)
			{
				if (text3 == "alipay")
				{
					this.PayOnline(num2.ToString(), text, text2);
				}
			}
		}
		else
		{
			base.ClientScript.RegisterStartupScript(typeof(string), "", "alert(请选择支付通道)", true);
		}
	}
	private void PayOnline(string money, string SysStr, string out_trade_no)
	{
		SortedDictionary<string, string> sortedDictionary = new SortedDictionary<string, string>();
		sortedDictionary.Add("partner", this.config["AlipayPartnerID"].IsNull(new object[0]));
		sortedDictionary.Add("key", this.config["AlipayKey"].IsNull(new object[0]));
		sortedDictionary.Add("seller_email", this.config["AlipayEmail"].IsNull(new object[0]));
		sortedDictionary.Add("return_url", string.Concat(new object[]
		{
			this.config["SiteUrl"],
			"/PayReturn/",
			SysStr,
			"/Alipay_Return.aspx"
		}));
		sortedDictionary.Add("notify_url", string.Concat(new object[]
		{
			this.config["SiteUrl"],
			"/PayReturn/",
			SysStr,
			"/Alipay_Notify.aspx"
		}));
		sortedDictionary.Add("payment_type", "1");
		sortedDictionary.Add("show_url", "");
		sortedDictionary.Add("out_trade_no", out_trade_no);
		sortedDictionary.Add("subject", "在线充值");
		sortedDictionary.Add("body", "在线充值");
		sortedDictionary.Add("total_fee", money);
		sortedDictionary.Add("paymethod", "");
		sortedDictionary.Add("defaultbank", "");
		sortedDictionary.Add("anti_phishing_key", "");
		sortedDictionary.Add("exter_invoke_ip", "");
		sortedDictionary.Add("extra_common_param", "");
		sortedDictionary.Add("buyer_email", "");
		sortedDictionary.Add("royalty_type", "");
		sortedDictionary.Add("royalty_parameters", "");
		Service service = new Service();
		string s = service.Create_direct_pay_by_user(sortedDictionary);
		base.Response.Write(s);
	}
	protected void AspNetPager1_PageChanged(object sender, EventArgs e)
	{
		if (this.Stamp == "data")
		{
			this.DataBindList();
		}
		if (this.Stamp == "search")
		{
			this.DataBindSearch();
		}
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		this.DataBindSearch();
		this.ViewState["Stamp"] = "search";
		this.actType = "1";
	}
}
